//
//  HistoryCalendarViewController.m
//  ZhangJiangJun
//
//  Created by FENGYL on 2017/1/21.
//  Copyright © 2017年 FENGYL. All rights reserved.
//

#import "HistoryCalendarViewController.h"
#import "MonitoringViewController.h"

#import <FSCalendar.h>

@interface HistoryCalendarViewController ()<FSCalendarDelegate,FSCalendarDataSource>

@property (strong, nonatomic) FSCalendar *calendar;

@end

@implementation HistoryCalendarViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setUpUI];
    
}

-(void)setUpUI{
    
    UIBarButtonItem * rightButtonItem = [[UIBarButtonItem alloc]initWithTitle:NSLocalizedString(LOCALIZABLE_TODAY, nil) style:UIBarButtonItemStylePlain target:self action:@selector(selectToday)];
    
    self.navigationItem.rightBarButtonItem = rightButtonItem;
    
    //初始化日历
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    FSCalendar *calendar = [[FSCalendar alloc] initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width)];
    calendar.dataSource = self;
    calendar.delegate = self;
    [self.view addSubview:calendar];
    self.calendar = calendar;
    
}

-(void)selectToday{
    
    [self.calendar setCurrentPage:[NSDate date]];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)calendar:(FSCalendar *)calendar didSelectDate:(NSDate *)date{
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.3 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        MonitoringViewController * monitoringViewController = [self.navigationController.viewControllers objectAtIndex:(self.navigationController.viewControllers.count) - 2];
        
        [monitoringViewController reloadValidAlarmArray];
        
        [monitoringViewController getAlertList:self.calendar.selectedDate];
        
        [monitoringViewController loadAlertLocation:self.calendar.selectedDate];
        
        [self.navigationController popViewControllerAnimated:YES];
        
    });
    
    
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
